package cn.tedu.property_management_system.service.Impl;


import cn.tedu.property_management_system.entity.Building;
import cn.tedu.property_management_system.entity.House;
import cn.tedu.property_management_system.entity.VO.AdministratorVO;
import cn.tedu.property_management_system.mapper.HouseMapper;
import cn.tedu.property_management_system.service.IHouseService;
import cn.tedu.property_management_system.utils.JsonPage;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Service
public class IHouseServiceImpl implements IHouseService {
    @Autowired
    HouseMapper mapper;


    public List<House> search(String room) {
        return mapper.searchSelect(room);
    }


    public List<House> selectList() {
        return mapper.selectUserList();
    }


    public int insertUser( House house) {
        System.out.println(house);
        List<House> h = mapper.searchSelect(house.getRoom());
        if (h.size() < 1) {
            house.setTime1(System.currentTimeMillis());
            mapper.insert(house);
            return 1;
        } else {
            return 2;
        }
    }


    public House selectUser( House house) {

        return mapper.selectId(house.getId());
    }


    public void update( House house) {
        log.debug(house+"df");
        house.setTime1(System.currentTimeMillis());
        mapper.update(house);

    }


    public void delete( House house) {

        mapper.delete(house.getId());

    }


    public int deletes( List<House> list) {

        if (list.size() > 0) {
            for (House house : list) {
                mapper.delete(house.getId());
            }
            return 1;
        } else {
            return 2;
        }
    }

    @Override
    public List<String> getHouseRoom() {
        List<String> room=mapper.getRoom();
        return room;
    }

    public JsonPage<House> pageSelect(Integer pageSize, Integer pageIndex){
        PageHelper.startPage(pageSize,pageIndex);
        List<House> list=mapper.selectUserList();
        return JsonPage.restPage(new PageInfo<>(list));
    }


}
